﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data.Common;
using DevExpress.LookAndFeel;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;

namespace Baubixinh_client
{
    static class Program
    {
        public static Database gobjDb = null;
        public static DbConnection gobjConn = null;
        public static DbTransaction gobjTrans = null;
        public static bool gblnLoggedIn = false;
        public static bool gblnAdminLoggedIn = false;
        public static string gstrCurrentUser = "";
        //public static clsEvents gevnApplication;
        //public static List<string> glstRoles;
        public static DataTable gobjDataDanhMuc = null;
        public static clsEvents gevnApplication;

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new frmMain());

            try
            {
                //clsCommon.fncMsgInfo("aaaaaaa");
                Application.EnableVisualStyles();
                //clsCommon.fncMsgInfo("aaaaaaa1111111111111111111");
                //Application.SetCompatibleTextRenderingDefault(false);
                //clsCommon.fncMsgInfo("bbbbbbbb");
                DevExpress.Skins.SkinManager.EnableFormSkins();
                DevExpress.UserSkins.BonusSkins.Register();
                //UserLookAndFeel.Default.SetSkinStyle("DevExpress Style");
                //UserLookAndFeel.Default.SetSkinStyle("Office 2010 Silver");
                UserLookAndFeel.Default.SetSkinStyle("Office 2010 Blue");
                //clsCommon.fncMsgInfo("cccccc");
                gobjDb = EnterpriseLibraryContainer.Current.GetInstance<Database>("Connection String");
                gobjConn = gobjDb.CreateConnection();
                gevnApplication = new clsEvents();
                //glstRoles = new List<string>();
                //clsCommon.fncMsgInfo("dddddd");
                try
                {
                    gobjConn.Open();
                }
                catch
                {
                    clsCommon.fncMsgError("Không thể kết nối được đến cơ sở dữ liệu. Xin hãy kiểm tra lại.");
                    using (frmConnectionSetting objSetting = new frmConnectionSetting())
                    {
                        objSetting.ShowDialog();
                        if (!objSetting.SettingSaved) return;
                    }
                }


                using (frmLogin objLogin = new frmLogin())
                {
                    objLogin.ShowDialog();
                    if (!objLogin.LoginSuccess)
                    {
                        gobjConn.Close();
                        return;
                    }
                }

                Application.Run(new frmMain());

                gobjConn.Close();
            }
            catch(Exception ex) {
                clsCommon.fncMsgError(ex.Message);
                clsCommon.fncMsgError("Xảy ra lỗi không mong muốn. Chương trình sẽ bị đóng."); }
        }
    }
}
